package com.juyu.miliao.api.util;

import java.util.Random;

public class ComputeRedPacketUtil {
	
	private static int pool = 0;
	
	synchronized public static int computeRedPacket(int userPacket) {
		// 1.获取随机数范围
		int min = (int) (userPacket * 0.2);
		int max = 0;
		if (userPacket * 1.4 > userPacket * 0.6 + pool)
			max = (int) (userPacket * 0.6 + pool);
		else
			max = (int) (userPacket * 1.4);
		// 2.获取随机值
		int randNum = getRandom(min, max);
		// 3.计算奖池数值
		pool = (int) (userPacket * 0.6 - randNum + pool);
		return randNum;
	}

	/**
	 * 获取指定范围随机数
	 * @param min 最小值
	 * @param max 最大值
	 * @return
	 */
	public static int getRandom(int min, int max) {
		Random rand = new Random();
		return  rand.nextInt(max - min + 1) + min;
	}

}
